
package com.chinacreator.c2etcd;

import io.etcd.jetcd.CloseableClient;
import io.etcd.jetcd.KeyValue;
import io.etcd.jetcd.cluster.MemberListResponse;
import io.etcd.jetcd.lease.LeaseKeepAliveResponse;
import io.etcd.jetcd.lease.LeaseRevokeResponse;
import io.etcd.jetcd.lease.LeaseTimeToLiveResponse;
import io.etcd.jetcd.lock.LockResponse;
import io.etcd.jetcd.lock.UnlockResponse;
import io.etcd.jetcd.maintenance.*;
import io.etcd.jetcd.watch.WatchResponse;

import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.function.Consumer;

/**
 * @Author: jack.liang
 **/
public interface EtcdClient {

    String CHARSET = "utf-8";

    void putKey(String key, String value) throws Exception;

    io.etcd.jetcd.KeyValue getKey(final String key) throws Exception;

    void deleteKey(String key);

    List<KeyValue> getKeyWithPrefix(String prefix);

    void deleteKeyWithPrefix(String prefix);

    void addWatcherListener(String key, Consumer<WatchResponse> onNext);

    long putKeyWithExpireTime(String key, String value, long expireTime);

    long putKeyWithLeaseId(String key, String value, long leaseId) throws Exception;

    long generatorLeaseId(long expireTime) throws Exception;

    CloseableClient keepAliveSingleLease(long leaseId);

    LeaseKeepAliveResponse keepAliveOnce(long leaseId) throws InterruptedException, ExecutionException;

    LeaseTimeToLiveResponse timeToLiveLease(long leaseId) throws InterruptedException, ExecutionException;

    LeaseRevokeResponse revokeLease(long leaseId) throws InterruptedException, ExecutionException;

    long getHeartBeatLeaseId() throws InterruptedException;

    LockResponse lock(String lockName) throws Exception;

    LockResponse lock(String lockName, long expireTime) throws Exception;

    LockResponse lockByLeaseId(String lockName, long leaseId) throws Exception;

    UnlockResponse unlock(String lockName) throws Exception;

    @Deprecated
    LockResponse lockByElectionLeader(String lockName) throws Exception;

//    void addWatcherListener(final String watcherKey, final boolean usePrefix, WatcherListener watcherListener);
//
//    void removeWatcherListener(final String watcherKey);

    void close() throws InterruptedException, ExecutionException;

    MemberListResponse listMember() throws InterruptedException, ExecutionException;

//     MemberAddResponse addMember(List<String> peerAddrs) throws InterruptedException, ExecutionException;

//     MemberRemoveResponse removeMember(long memberID) throws InterruptedException, ExecutionException;

//     DefragmentResponse defragmentMember(String endpoint) throws InterruptedException, ExecutionException;

//     MoveLeaderResponse moveLeader(long transfereeID) throws InterruptedException, ExecutionException;

    StatusResponse statusMember(String endpoint) throws InterruptedException, ExecutionException;

    AlarmResponse alarmDisarm(AlarmMember member) throws InterruptedException, ExecutionException;

    AlarmResponse listAlarms() throws InterruptedException, ExecutionException;

}

